package service

import (
	"fmt"
)

func ListPrintln() {

	var a []int
	a = make([]int, 5)
	a[0] = 2
	a[1] = 1
	a[2] = 6
	a[3] = 7
	a[4] = 8

	//a := []string{"1", "2", "3", "4", "heaven"}
	//fmt.Println(a)

	fmt.Println(a[3])
	//var i int
	for i := 0; i < len(a); i++ {
		fmt.Println(a[i])
	}
}
func FindMin(a []int) int {

	a = make([]int, 7)
	a[0] = 2
	a[1] = 1
	a[2] = 3
	a[3] = 8
	a[4] = 100
	a[5] = 7
	a[6] = 8
	fmt.Println(a)

	min := 10000
	for i := 0; i < len(a); i++ {
		if a[i] < min {
			min = a[i]
		}
	}
	return min
}

func ListInsert(a []int, num int) []int {
	var G []int
	G = make([]int, len(a)+1)
	for i := 0; i < len(a); i++ {
		G[i] = a[i]
	}
	G[len(a)] = num
	return G
}
func ListInsert2(a []int, n int, num int) []int {
	var G []int
	G = make([]int, len(a)+1)
	for i := 0; i < n; i++ {
		G[i] = a[i]
	}
	G[n] = num
	for i := n; i < len(a)+1; i++ {
		G[i] = a[i-1]
	}
	return G
}

func ListExchange(a []int, n int, m int) []int {
	//todo 交换 a[n] 和 a[m]的值
	//a 1,2,3,4,5   n = 2, m = 3
	// a[2],a[3]   1,2,4,3,5
	return a
}

func add(a int, b int) int {
	return a + b
}

func MaxExchange(a []int) []int {
	max := a[0]
	x := 0
	for i := 0; i < len(a); i++ {
		if a[i] > max {
			max = a[i]
			x = i
		}
	}

	tmp := a[0]

	a[0] = a[x]
	a[x] = tmp

	return a
}

func Sort(a []int) []int {

	for i := 0; i < len(a)-1; i++ {

		for j := i + 1; j < len(a); j++ {
			if a[i] > a[j] {
				a[i], a[j] = a[j], a[i]
			}

		}

	}
	return a
}
